package com.ps.dao.person;

import java.sql.Timestamp;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ps.pojo.person.EmployeeAttendance;

/**
 * A data access object (DAO) providing persistence and search support for
 * EmployeeAttendance entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.ps.pojo.person.EmployeeAttendance
 * @author MyEclipse Persistence Tools
 */

public class EmployeeAttendanceDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(EmployeeAttendanceDAO.class);
	// property constants
	public static final String EMPLOYEE_ID = "employeeId";
	public static final String YEAR = "year";
	public static final String MONTH = "month";
	public static final String SHOULD_ARRIVE = "shouldArrive";
	public static final String ACTUAL_ARRIVAL = "actualArrival";
	public static final String BEING_LATE = "beingLate";
	public static final String ABSENTEEISM = "absenteeism";
	public static final String LEAVE_EARLY = "leaveEarly";
	public static final String ASK_FOR_LEAVE = "askForLeave";
	public static final String INPUTER_ID = "inputerId";

	protected void initDao() {
		// do nothing
	}

	public void save(EmployeeAttendance transientInstance) {
		log.debug("saving EmployeeAttendance instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(EmployeeAttendance persistentInstance) {
		log.debug("deleting EmployeeAttendance instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public EmployeeAttendance findById(java.lang.Integer id) {
		log.debug("getting EmployeeAttendance instance with id: " + id);
		try {
			EmployeeAttendance instance = (EmployeeAttendance) getHibernateTemplate()
					.get("com.ps.pojo.person.EmployeeAttendance", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(EmployeeAttendance instance) {
		log.debug("finding EmployeeAttendance instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding EmployeeAttendance instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from EmployeeAttendance as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByEmployeeId(Object employeeId) {
		return findByProperty(EMPLOYEE_ID, employeeId);
	}

	public List findByYear(Object year) {
		return findByProperty(YEAR, year);
	}

	public List findByMonth(Object month) {
		return findByProperty(MONTH, month);
	}

	public List findByShouldArrive(Object shouldArrive) {
		return findByProperty(SHOULD_ARRIVE, shouldArrive);
	}

	public List findByActualArrival(Object actualArrival) {
		return findByProperty(ACTUAL_ARRIVAL, actualArrival);
	}

	public List findByBeingLate(Object beingLate) {
		return findByProperty(BEING_LATE, beingLate);
	}

	public List findByAbsenteeism(Object absenteeism) {
		return findByProperty(ABSENTEEISM, absenteeism);
	}

	public List findByLeaveEarly(Object leaveEarly) {
		return findByProperty(LEAVE_EARLY, leaveEarly);
	}

	public List findByAskForLeave(Object askForLeave) {
		return findByProperty(ASK_FOR_LEAVE, askForLeave);
	}

	public List findByInputerId(Object inputerId) {
		return findByProperty(INPUTER_ID, inputerId);
	}

	public List findAll() {
		log.debug("finding all EmployeeAttendance instances");
		try {
			String queryString = "from EmployeeAttendance";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public EmployeeAttendance merge(EmployeeAttendance detachedInstance) {
		log.debug("merging EmployeeAttendance instance");
		try {
			EmployeeAttendance result = (EmployeeAttendance) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(EmployeeAttendance instance) {
		log.debug("attaching dirty EmployeeAttendance instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(EmployeeAttendance instance) {
		log.debug("attaching clean EmployeeAttendance instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static EmployeeAttendanceDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (EmployeeAttendanceDAO) ctx.getBean("EmployeeAttendanceDAO");
	}
}